local GameDB = import(".GameDB")

function GameDB:queryGuildCreateById( id )
	local itemRes = self:getCachedValue("guild_creat_icon",id)
	return itemRes
end

function GameDB:queryGuildPosById( id )
	local itemRes = self:getCachedValue("guild_position",id)
	return itemRes
end

function GameDB:queryGuildLvById( id )
	local itemRes = self:getCachedValue("guild_level",id)
	return itemRes
end

function GameDB:queryGuildChallengeById( id )
	local itemRes = self:getCachedValue("guild_challenge",id)
	return itemRes
end

function GameDB:queryGuildDonateById( id )
	local itemRes = self:getCachedValue("guild_donate",id)
	return itemRes
end

--读表获得最高贡献等级
function GameDB:getMaxGuildDonateLv()
	local donates = self:getCachedValues("guild_donate")
	local maxLv = 1
	for _, donate in pairs(donates) do
		if tonumber(donate.ID) > maxLv then
			maxLv = tonumber(donate.ID)
		end
	end
	return maxLv
end


--获取所有的公会天赋
function GameDB:queryGuildTalents()
	local talnets = self:getCachedValues("guild_skill",nil,function(l,r)
        return tonumber(l.ID) < tonumber(r.ID)
    end)
	return talnets
end

--获取势力信息
function GameDB:queryGuildForceInfos()
	local forceInfos = self:getCachedValues("force",nil,function(l,r)
		return tonumber(l.ID) > tonumber(r.ID)
	end)
	return forceInfos
end

--获取所有官职
function GameDB:queryElevatePeerages()
	local itemRes = self:getCachedValues("force_peerage",nil,function(l,r)
		return tonumber(l.ID) < tonumber(r.ID)
	end)
	return itemRes
end

--根据贵族id获取信息
function GameDB:queryPeerageById(id)
	local itemRes = self:getCachedValue("force_peerage",id)
	return itemRes
end

--根据势力等级获取势力信息 经验上限等
function GameDB:queryForceInfoByLv(lv)
	local itemRes = self:getCachedValue("force",lv)
	return itemRes
end

--根据爵位ID 可以获知可以分配的官职信息
function GameDB:getConferTitlesById(id)
	local itemRes = self:getCachedValue("force_peerage",id)
	return itemRes.governablePeerage
end

--服务器开放时间决定统治力或者繁荣度上限
function GameDB:getForceLimitInfos()
	return self:getCachedValues("force_limit",nil,function(l,r)
		return tonumber(l.ID) < tonumber(r.ID)
	end)
end

function GameDB:getForceLimitInfoByDay(day)
	local forceLimitInfos = self:getForceLimitInfos()
	local tempVal = nil
	for k,v in ipairs(forceLimitInfos) do
		tempVal = v
		if tonumber(v.limitDay) >= tonumber(day) then
			return v
		end
	end
	return tempVal
end

-- 根据据点ID获取据点信息
function GameDB:getStrongholdInfoById(id)
	return self:getCachedValue("guild_battlefield", id)
end

-- 根据地图ID获取据点信息
function GameDB:getStrongholdInfoByMapId(mapId)
	local holds = self:getCachedValues("guild_battlefield")
	for _, hold in pairs(holds) do
		if tonumber(hold.mapID) == mapId then
			return hold
		end
	end
end

return GameDB
